﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using DC2010;
using DC2010.Objects;
using DC2010.Objects.Data;
using RolePlaying;
using Microsoft.Xna.Framework;
using Xna.Base;

namespace DC2010
{
    public partial class Hud
    {

        private void DrawActionPanels()
        {
            SpriteBatch spriteBatch = screenManager.SpriteBatch;

            //get info about activated action panels
            bool bActionPanelActivated = false;
            foreach (CreatureData c in Root.I.GameSystem.Party.MembersData)
            {
                if ((c.ActionOptionsAreDisplayed_Right) || (c.ActionOptionsAreDisplayed_Left))
                {
                    bActionPanelActivated = true;
                    break;
                }
            }

            if (!bActionPanelActivated)
            {
                //int PanelCount = Root.I.GameSystem.Party.Count;
                HandlePanel(1);
                HandlePanel(2);
                HandlePanel(3);
                HandlePanel(4);
            }

        }


        public void HandlePanel(int panelNumber)
        {
            int PanelCount = Root.I.GameSystem.Party.Members.Count;
            SpriteBatch spriteBatch = screenManager.SpriteBatch;

            if (PanelCount >= panelNumber)
            {
                CreatureData c = Root.I.GameSystem.Party.GetCreatureByIndex(panelNumber);
                ItemData i1 = c.Inventory.GetItemAtPosition(CarryLocations.RightHand).GetItemDataFromCode();
                ItemData i2 = c.Inventory.GetItemAtPosition(CarryLocations.LeftHand).GetItemDataFromCode();

                bool IsActiveLeft = false;
                bool IsActiveRight = false;

                if (i1 != null)
                {
                    if (i1.Combo.Count >= 1)
                    {
                        spriteBatch.Draw(TM.GetTex("Interface/Panel"), RM.Get("ActionPanel_" + panelNumber + "" + 1).GetVector(), Tools.GetColor(c.Gfx.Color));
                        TM.GetAnimation(i1.Gfx.Icon.Texture).Draw(spriteBatch, RM.Get("ActionPanel_" + panelNumber + "" + 1).GetVector() + new Vector2(4, 9), 0f, Color.Black);
                        IsActiveRight = true;
                    }
                }

                if (i2 != null)
                {
                    if (i2.Combo.Count >= 1)
                    {
                        spriteBatch.Draw(TM.GetTex("Interface/Panel"), RM.Get("ActionPanel_" + panelNumber + "" + 2).GetVector(), Tools.GetColor(c.Gfx.Color));
                        TM.GetAnimation(i2.Gfx.Icon.Texture).Draw(spriteBatch, RM.Get("ActionPanel_" + panelNumber + "" + 2).GetVector() + new Vector2(4, 9), 0f, Color.Black);
                        IsActiveLeft = true;
                    }
                }

                if (!IsActiveRight)
                {
                    spriteBatch.Draw(TM.GetTex("Interface/Panel"), RM.Get("ActionPanel_" + panelNumber + "" + 1).GetVector(), Color.Lerp(Color.Black, Tools.GetColor(c.Gfx.Color), 0.3f));
                }

                if (!IsActiveLeft)
                {
                    spriteBatch.Draw(TM.GetTex("Interface/Panel"), RM.Get("ActionPanel_" + panelNumber + "" + 2).GetVector(), Color.Lerp(Color.Black, Tools.GetColor(c.Gfx.Color), 0.3f));
                }
            }
        }

        private void DrawActivatedActionPanels()
        {
            CreatureData workingCreature = null;
            //get user which has activated action panels
            foreach (CreatureData c in Root.I.GameSystem.Party.MembersData)
            {
                if ((c.ActionOptionsAreDisplayed_Left) || (c.ActionOptionsAreDisplayed_Right))
                {
                    workingCreature = c;
                    break;
                }
            }

            if (workingCreature != null)
            {
                ItemData itm = null;
                if (workingCreature.ActionOptionsAreDisplayed_Left)
                    itm = workingCreature.Inventory.GetItemAtPosition(CarryLocations.LeftHand).GetItemDataFromCode();

                if (workingCreature.ActionOptionsAreDisplayed_Right)
                    itm = workingCreature.Inventory.GetItemAtPosition(CarryLocations.RightHand).GetItemDataFromCode();

                if (itm != null)
                {
                    //how many boxes we will draw
                    int count = itm.Combo.Count;

                    SpriteBatch spriteBatch = screenManager.SpriteBatch;

                    if (count >= 1)
                    {
                        spriteBatch.Draw(TM.GetTex("Interface/ActionPanel"), RM.Get("ActionPanel").GetVector(), Color.White);
                        ActionData ad = Root.I.ActionSystem.GetData(itm.Combo[0]);
                        spriteBatch.DrawString(Fonts.DebugFont, ad.ShortName, RM.Get("ActionPanel").GetVector() + new Vector2(10, 22), Color.White);
                    }

                    if (count >= 2)
                    {
                        spriteBatch.Draw(TM.GetTex("Interface/Action"), RM.Get("Action_1").GetVector(), Color.White);
                        ActionData ad = Root.I.ActionSystem.GetData(itm.Combo[1]);

                        spriteBatch.DrawString(Fonts.DebugFont, ad.ShortName, RM.Get("Action_1").GetVector() + new Vector2(10, 6), Color.White);
                    }

                    if (count >= 3)
                    {
                        spriteBatch.Draw(TM.GetTex("Interface/Action"), RM.Get("Action_2").GetVector(), Color.White);
                        ActionData ad = Root.I.ActionSystem.GetData(itm.Combo[2]);

                        spriteBatch.DrawString(Fonts.DebugFont, ad.ShortName, RM.Get("Action_2").GetVector() + new Vector2(10, 6), Color.White);
                    }

                    if (count >= 4)
                    {
                        spriteBatch.Draw(TM.GetTex("Interface/Action"), RM.Get("Action_3").GetVector(), Color.White);
                        ActionData ad = Root.I.ActionSystem.GetData(itm.Combo[3]);
                        spriteBatch.DrawString(Fonts.DebugFont, ad.ShortName, RM.Get("Action_3").GetVector() + new Vector2(10, 6), Color.White);
                    }
                }
            }
        }


    }
}
